import 'package:flutter/material.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'entity/product.dart';
import 'HomeDetail/ProductDetailPage.dart';

class HomePage extends StatelessWidget {
  final List<String> imgList = [
    'assets/images/雷克萨斯SL.jpg',
    'assets/images/迈巴赫S级.jpg',
    'assets/images/宝马X5.jpg',
  ];

  final List<Product> productList = [
    Product(
      id: '1',
      title: '奥迪Q5L',
      description: '这是商品1的描述',
      price: 11111,
      imageUrl: 'assets/images/奥迪Q5L.jpg',
      brand: '哇哈哈',
      category: '类别1',
    ),
    Product(
      id: '2',
      title: '保时捷718',
      description: '这是商品2的描述',
      price: 22222,
      imageUrl: 'assets/images/保时捷718.jpg',
      brand: '苦哈哈',
      category: '类别2',
    ),
    Product(
      id: '3',
      title: '奥迪A8',
      description: '这是商品3的描述',
      price: 33333,
      imageUrl: 'assets/images/奥迪A8.jpg',
      brand: '苦哈哈',
      category: '类别2',
    ),
    Product(
      id: '4',
      title: '问界M7',
      description: '这是商品4的描述',
      price: 44444,
      imageUrl: 'assets/images/问界M7.jpg',
      brand: '苦哈哈',
      category: '类别2',
    ),
    Product(
      id: '5',
      title: '小米su7',
      description: '这是商品5的描述',
      price: 55555,
      imageUrl: 'assets/images/xiaomi SU7.jpg',
      brand: '苦哈哈',
      category: '类别2',
    ),
    Product(
      id: '6',
      title: 'model y',
      description: '这是商品6的描述',
      price: 66666,
      imageUrl: 'assets/images/model y.jpg',
      brand: '苦哈哈',
      category: '类别2',
    ),
    Product(
      id: '7',
      title: '宋Plus',
      description: '这是商品7的描述',
      price: 77777,
      imageUrl: 'assets/images/宋Plus.jpg',
      brand: '苦哈哈',
      category: '类别2',
    ),
    Product(
      id: '8',
      title: '保时捷911',
      description: '这是商品8的描述',
      price: 88888,
      imageUrl: 'assets/images/保时捷911.jpg',
      brand: '苦哈哈',
      category: '类别2',
    ),
    Product(
      id: '9',
      title: 'AMG GT',
      description: '这是商品9的描述',
      price: 99999,
      imageUrl: 'assets/images/AMG GT.jpg',
      brand: '苦哈哈',
      category: '类别2',
    ),

  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white60,
      appBar: AppBar(
        backgroundColor: Colors.blueGrey,
        title: Text('商品首页'),
      ),
      body: ListView(
        children: [
          CarouselSlider(
            options: CarouselOptions(
              aspectRatio: 2.0,
              enlargeCenterPage: true,
              autoPlay: true,
            ),
            items: imgList.map((item) => Container(
              child: Center(
                  child: Image.asset(item, fit: BoxFit.cover, width: 1000)
              ),
            )).toList(),
          ),
          ListView.builder(
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            itemCount: productList.length,
            itemBuilder: (BuildContext context, int index) {
              return ListTile(
                leading: Image.asset(productList[index].imageUrl),
                title: Text(productList[index].title),
                subtitle: Text('价格: ' + productList[index].price.toString() + ' 公司: ' + productList[index].brand),
                onTap: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => ProductDetailPage(product: productList[index]),
                    ),
                  );
                },
              );
            },
          ),
        ],
      ),
    );
  }
}